package org.dromara.mall.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import jakarta.validation.constraints.NotEmpty;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.dromara.common.core.domain.R;
import org.dromara.common.core.validate.AddGroup;
import org.dromara.common.core.validate.EditGroup;
import org.dromara.common.idempotent.annotation.RepeatSubmit;
import org.dromara.common.log.annotation.Log;
import org.dromara.common.log.enums.BusinessType;
import org.dromara.common.web.core.BaseController;
import org.dromara.mall.domain.MallGoodsSpecVal;
import org.dromara.mall.service.IMallGoodsSpecValService;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;


/**
 * 商品规格
 *
 * @author Lion Li
 * @date 2024-05-20
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/mall/goodsSpecVal")
@Slf4j
public class MallGoodsSpecValController extends BaseController {

    private final IMallGoodsSpecValService mallGoodsSpecValService;

    /*新增*/
    @SaCheckPermission("mall:goodsSpecVal:add")
    @Log(title = "规格属性", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody MallGoodsSpecVal bo) {
        return toAjax(mallGoodsSpecValService.insertByBo(bo));
    };
    /*编辑*/
    @SaCheckPermission("mall:goodsSpecVal:edit")
    @Log(title = "规格属性", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody MallGoodsSpecVal bo) {
        return toAjax(mallGoodsSpecValService.updateByBo(bo));
    };

    /*单条删除*/
    @DeleteMapping("/{ids}")
    @SaCheckPermission("mall:goodsSpecVal:remove")
    @Log(title = "规格属性", businessType = BusinessType.DELETE)
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable Long[] ids) {
        return toAjax(mallGoodsSpecValService.deleteWithValidByIds(List.of(ids), true));
    }
}
